home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v10n20.arc / DELMC.ARC / DELMC.ASM next >
Assembly Source File  |  1991-10-28  |  5KB  |  118 lines

  1.               PAGE  96,132
  2. ;**********************************************************************
  3. ; DELMC.ASM                      Clipper UDF to delay n timer ticks
  4. ; Author..: Sal Ricciardi
  5. ;
  6. ; Use this file for program delays that are the same regardless
  7. ; of CPU type and speed.  Relies on the BIOS timer tick count.
  8. ; Maximum delay is 65535 ticks (about 1 hr).  Does not validate
  9. ; passed parameters.
  10. ;
  11. ; This version should work better under multitasking systems like
  12. ; Desqview or Microsoft Windows.
  13. ;
  14. ; Usage:
  15. ;
  16. ; DELAY(10*18.2)             && for 10 seconds
  17. ;
  18. ; Create .OBJ with:   TASM delmc  (Borland Turbo Assembler 2.5)
  19. ;
  20. ; To link into your Clipper 5 app:
  21. ;   RTLINK FILE yourapp.obj, DELMC.OBJ LIB CLIPPER, EXTEND
  22. ;
  23. ; To link into your Clipper Summer 87 app:
  24. ;   PLINK86 FILE yourapp.obj, DELMC.OBJ LIB CLIPPER, EXTEND
  25. ;
  26. ;**********************************************************************
  27.               .MODEL LARGE
  28.               EXTRN __parni:FAR, __ret:FAR
  29.               PUBLIC delay
  30.               .CODE
  31.  
  32. Timerhigh     EQU   WORD PTR ds:[06eh]
  33. Timerlow      EQU   WORD PTR ds:[06ch]
  34.  
  35. delay         PROC  FAR                         ;entry point
  36.               push  ax                          ;save registers
  37.               push  bx                          ;
  38.               push  cx                          ;
  39.               push  dx                          ;
  40.               push  es                          ;
  41.               push  ds                          ;
  42.               mov   ax,1                        ;routine to get a numeric
  43.               push  ax                          ;parameter from Clipper,
  44.               call  __parni                     ;converted to an int in
  45.               add   sp,2                        ;ax
  46.               mov   cx,ax                       ;put it in cx
  47.               jcxz  d999                        ;skip if cx==0
  48.               mov   ax,040h                     ;
  49.               mov   ds,ax                       ;ds == 040h
  50. ;
  51. ; Get current timer count.  Make sure we get both low and high at the same time.
  52. ;
  53.               cli                               ;interrupts off
  54.               mov   ax,Timerlow                 ;get current tick count low
  55.               mov   dx,Timerhigh                ;get current tick count high
  56.               sti                               ;interrupts on
  57. ;
  58. ; Add the delay value to form the target timer count.
  59. ;
  60.               add   ax,cx                       ;add ticks parameter to form
  61.               adc   dx,0                        ;target
  62.                                                 ;
  63.               cmp   dx,018h                     ;q. target past midnight?
  64.               jb    d500                        ;a. no, handle normally
  65.               ja    d400                        ;a. yes, go handle special case
  66.                                                 ;
  67.               cmp   ax,0B0h                     ;q. target past midnight?
  68.               jb    d500                        ;a. no, handle normally
  69. ;
  70. ; Target is past midnight.  Adjust target and wait for midnight.
  71. ;
  72. d400:
  73.               sub   ax,0B0h                     ;subtract max to adjust the
  74.               sbb   dx,018h                     ;target
  75. d410:                                           ;is past midnight
  76.               cmp   Timerhigh,016h              ;q. cross midnight yet?
  77.               jae   d410                        ;a. no,loop
  78. ;
  79. ; Delay until target time.  This is where we attempt some level of insulation
  80. ; from multitasker interruption.
  81. ;
  82. d500:
  83.               cmp   Timerhigh,dx                ;q. timerhigh reach the target?
  84.               je    d510                        ;a. yes, check timerlow
  85. ;
  86. ; Timerhigh could be greater than target if a multitasker had
  87. ; control for awhile, and we just returned
  88. ;
  89.               ja    d999                        ;a. greater than, we're done
  90. ;
  91. ; Could be less than by more than one if multitasker had control for awhile,
  92. ; and during that time midnight passed
  93.                                                 ;a. timerhigh is less than target
  94.               mov   bx,dx                       ;get target in bx
  95.               sub   bx,Timerhigh                ;subtract current timerhigh
  96.                                                 ;
  97.               cmp   bx,1                        ;q. more than one less?
  98.               jne   d999                        ;a. yes, must be done
  99.  
  100.               jmp   d500                        ;a. go check again
  101. d510:                                           ;
  102.               cmp   Timerlow,ax                 ;q. timerlow less than target?
  103.               jb    d510                        ;a. yes, loop
  104. ;
  105. ; Clean up and return to caller
  106. ;
  107. d999:                                           ;
  108.               call  __ret                       ;post NIL return value
  109.               pop   ds                          ;restore ds
  110.               pop   es                          ;restore registers
  111.               pop   dx                          ;
  112.               pop   cx                          ;
  113.               pop   bx                          ;
  114.               pop   ax                          ;
  115.               ret                               ;return to caller
  116. delay         ENDP
  117.               END
  118.